#ifndef GAMEWINDOW_H
#define GAMEWINDOW_H

#include <QGraphicsView>
#include <QGraphicsScene>
#include <QTimer>
#include <QElapsedTimer>
#include <QSoundEffect>
#include<QRandomGenerator>
#include "player.h"
#include "gamemenu.h"
#include "gamescore.h"

class GameWindow : public QGraphicsView
{
    Q_OBJECT

public:
    GameWindow(QWidget *parent = nullptr);
    ~GameWindow();

protected:
    void keyPressEvent(QKeyEvent *event) override;

private slots:
    void startGame();
    void showScore();
    void returnToMenu();
    void update();
    void spawnObstacle();

private:
    QGraphicsScene *gameScene;
    GameMenu *menuScene;
    GameScore *scoreScene;
    Player *player;
    QTimer *gameTimer;
    QTimer *spawnTimer;
    QElapsedTimer *elapsedTimer;
    QElapsedTimer *scoreTimer;
    QSoundEffect *bgMusic;
    QSoundEffect *jumpSound;
    QSoundEffect *crashSound;

    int gameSpeed;
    int score;
    bool gameOver;

    void initGame();
    void initPlayer();
    void initTimers();
    void initSounds();
    void checkCollisions();
    void cleanGame();
};

#endif // GAMEWINDOW_H
